<template>
	<view>
		<view class="feedback">
			<navbar title="意见反馈"></navbar>
			<view class="content-wrapper">
				<textarea class="content" placeholder="请输入您要反馈的问题（5-500字以内）" placeholder-style="color: #aaa" v-model="content"></textarea>
			</view>
			<view class="upload-wrapper">
				<view class="title">请提供问题的截图和照片（选填）</view>
				<view class="upload-box flex fww">
					<view class="upload-list" v-for="(item, index) in imageList" :key="index" @click="uploadImage(index)">
						<image :src="item"></image>
					</view>
					<view class="upload-list" @click="uploadImage(-1)" v-if="imageList.length < 9">
						<image src="../../static/upload.png" mode=""></image>
					</view>
				</view>
			</view>
			<view class="mobile-box fa jcsb">
				<view>联系方式</view>
				<view class="mobile-right fa">
					<input type="text" placeholder="请输入手机号" v-model="mobile" />
					<image class="close" src="../../static/close2.png" mode="" @click="delMobile"></image>
				</view>
			</view>
		</view>
		<view class="fixed-bottombar">
			<view class="bottombar-box fa fdc jcc">
				<view class="confirm-button" @click="addConfirm">提交</view>
				<view class="record" @click="utils.navTo('/pages/mine/feedback_record')">提交记录</view>
			</view>
			<view class="fixed-place"></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				image: '',
				content: '',
				imageList: [],
				mobile: '',
				lock: true
			};
		},
		methods: {
			uploadImage(index) {
				uni.chooseImage({
					count: 1,
					mediaType: ['image'],
					sourceType: ['album', 'camera'],
					success: result => {
						this.api.uploadFileFunc(result.tempFiles[0].path).then(res => {
							if(index < 0) {
								this.imageList.push(res.url)
							}else {
								this.imageList.splice(index, 1, res.url)
							}
						})
					}
				})
			},
			delMobile() {
				this.mobile = ''
			},
			addConfirm() {
				if(!this.content) return uni.showToast({
					title: '请输入您要反馈的问题',
					icon: 'none'
				})
				if (!/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.mobile)) return uni.showToast({
					title: '请输入正确的手机号',
					icon: 'none'
				})
				if(!this.lock) return false
				this.lock = false
				this.api.feedbackFunc({
					content: this.content,
					img: this.imageList.join(),
					phone: this.mobile
				}).then(res => {
					if(res.code == 200) {
						uni.showToast({
							title: res.msg
						})
						this.content = ''
						this.imageList = []
						this.mobile = ''
						setTimeout(() => {
							uni.navigateBack()
						}, 1500)
					}else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
						this.lock = true
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.feedback{
		padding-bottom: 2rpx;
		background: #fff;
	}
	.content-wrapper{
		padding: 24rpx 24rpx 0;
		.content{
			padding: 28rpx 24rpx;
			width: 100%;
			height: 332rpx;
			border-radius: 10rpx;
			background: #FAFAFA;
			box-sizing: border-box;
		}
	}
	.upload-wrapper{
		margin: 24rpx;
		padding: 28rpx 24rpx;
		border-radius: 10rpx;
		background: #FAFAFA;
		.title{
			padding-bottom: 28rpx;
			border-bottom: 2rpx solid #E6E6E6;
		}
		.upload-box{
			margin-top: 26rpx;
		}
		.content{
			width: auto;
			height: 100rpx;
			background-color: #F9F9F9;
		}
		.upload-list{
			margin-right: 16rpx;
			margin-bottom: 16rpx;
			width: 152rpx;
			height: 152rpx;
			&:nth-child(3n) {
				margin-right: 0;
			}
			image{
				width: 152rpx;
				height: 152rpx;
			}
		}
	}
	.mobile-box{
		margin: 0 30rpx 30rpx;
		padding: 20rpx;
		border-radius: 10rpx;
		background: #FAFAFA;
		input{
			text-align: right;
		}
		.close{
			margin-left: 14rpx;
			width: 32rpx;
			height: 32rpx;
		}
	}
	.fixed-bottombar{
		.bottombar-box{
			z-index: 98;
			position: fixed;
			bottom: 0;
			bottom: env(safe-area-inset-bottom);
			left: 0;
			right: 0;
			padding: 0 24rpx;
			height: 240rpx;
			background-color: var(--bodybg);
			z-index: 999;
			.confirm-button{
				width: 100%;
				height: 88rpx;
				line-height: 88rpx;
				border-radius: 44px;
				font-size: 30rpx;
				text-align: center;
				color: #fff;
				background: var(--theme);
			}
			.record{
				margin-top: 28rpx;
				color: #315F94;
			}
		}
		.fixed-place{
			height: 240rpx;
		}
	}
</style>
